#登录业务

import allure
from page.page_index import PageIndex #导入UI1
from page.page_login import PageLogin #导入ui2
from page.page_user import PageUser #导入ui3

class ServerLogin(object):
    def __init__(self,driver,base_url):
        #从script层接收diver、base_url
        self.driver=driver
        self.base_url=base_url
        #定义UI1页面的页面对象
        self.ui1=PageIndex(self.driver,self.base_url)
        # 定义UI2页面的页面对象
        self.ui2 = PageLogin(self.driver, self.base_url)
        #定义ui3页面的页面对象
        self.ui3=PageUser(self.driver,self.base_url)

    def servier_login_001(self,d):
        #调用ui1类相关函数来完成UI1上各个ui操作
        self.ui1.openUrl()
        self.ui1.click_login()
        #调用ui2类相关函数来完成ui2的各个UI操作
        self.ui2.input_zanhao(d["zanhao"])
        self.ui2.input_pwd(d["pwd"])
        self.ui2.click_login()
        #调用ui3类相关函数来完成ui3的各个UI操作
        siji=self.ui3.getH2EleText()
        return siji==d["yuqi"]

    def servier_login_002(self,d):
        #调用ui1类相关函数来完成UI1上各个ui操作
        allure.attach("", "打开首页")
        self.ui1.openUrl()
        allure.attach("", "点击“首页”页面的登录按钮")
        self.ui1.click_login()
        #调用ui2类相关函数来完成ui2的各个UI操作
        allure.attach("",f"输入账号:{d['zanhao']}")
        self.ui2.input_zanhao(d["zanhao"])
        allure.attach("", f"输入密码:{d['pwd']}")
        self.ui2.input_pwd(d["pwd"])
        allure.attach("", "点击登录按钮")
        self.ui2.click_login()
        imgName=self.ui2.savePng3("登录",d["key"]) #"登录_K001_20240911113818"
        siji=self.ui2.getErrorTipDivText()
        allure.attach(open(f'./screen/{imgName}.png', 'rb').read(), "点击登录按钮后的UI截图",allure.attachment_type.PNG)
        allure.attach("", "实际结果="+siji)
        return siji==d["yuqi"]

    def servier_login_003(self,d):
        #调用ui1类相关函数来完成UI1上各个ui操作
        self.ui1.openUrl()
        self.ui1.click_login()
        #调用ui2类相关函数来完成ui2的各个UI操作
        self.ui2.input_zanhao(d["zanhao"])
        self.ui2.input_pwd(d["pwd"])
        self.ui2.click_login()
        siji=self.ui2.getZanhaoClass()
        return d["yuqi"] in siji

    def servier_login_004(self,d):
        #调用ui1类相关函数来完成UI1上各个ui操作
        self.ui1.openUrl()
        self.ui1.click_login()
        #调用ui2类相关函数来完成ui2的各个UI操作
        self.ui2.input_zanhao(d["zanhao"])
        self.ui2.input_pwd(d["pwd"])
        self.ui2.click_login()
        siji=self.ui2.getPwdClass()
        return d["yuqi"] in siji
